import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/api/home.dart';
import 'package:flutter_enjoy_plus/utils/Toast.dart';
import 'package:flutter_html/flutter_html.dart';

class NoticeDetail extends StatefulWidget {
  const NoticeDetail({super.key});

  @override
  State<NoticeDetail> createState() => _NoticeDetailState();
}

class _NoticeDetailState extends State<NoticeDetail> {
  Map notifyDetail = {};
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  // 依赖的数据发生改变执行，例如路由传递参数等
  @override
  didChangeDependencies() {
    super.didChangeDependencies();
    final data = ModalRoute.of(context)?.settings.arguments;
    if (data != null) {
      _getDetial((data as Map<String, dynamic>)['id']);
    }
  }

  // 获取公告详情
  _getDetial(id) async {
    final res = await getAnnounceDetailAPI(id);
    setState(() {
      notifyDetail = res;
    });
    // PromptAction.showToast('获取公告详情成功');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('公告详情'),
      ),
      body: ListView(children: [
        Container(
          padding: const EdgeInsets.all(10),
          child:
              Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
            // 标题
            Text(notifyDetail['title'] ?? '',
                style: const TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                )),
            const SizedBox(height: 10),
            Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
              Text(
                notifyDetail['creatorName'] ?? '',
                style: const TextStyle(color: Colors.grey),
              ),
              Text(
                notifyDetail['createdAt'] ?? '',
                style: const TextStyle(color: Colors.grey),
              )
            ]),
            const SizedBox(height: 10),
            // 内容
            Html(
              data: notifyDetail['content'] ?? "",
            )
          ]),
        )
      ]),
    );
  }
}
